package com.ericsson.enap.modules.autoCheck.service.impl;

import com.ericsson.enap.modules.autoCheck.entity.AutoCheck;
import com.ericsson.enap.modules.autoCheck.entity.AutoCheckItem;
import com.ericsson.enap.modules.autoCheck.entity.AutocheckMaxtime;
import com.ericsson.enap.modules.autoCheck.entity.AutomqDict;
import com.ericsson.enap.modules.autoCheck.entity.AutomqDictIms;
import com.ericsson.enap.modules.autoCheck.entity.NetAutoCheck;
import com.ericsson.enap.modules.autoCheck.entity.NetIms;
import com.ericsson.enap.modules.autoCheck.entity.VisAutoCheckLog;
import com.ericsson.enap.modules.autoCheck.entity.VisAutoCheckMq;
import com.ericsson.enap.modules.autoCheck.entity.VisAutoCheckMqIdGenerator;
import com.ericsson.enap.modules.autoCheck.entity.VisExcel;
import com.ericsson.enap.modules.autoCheck.entity.VisExcelModuleDetail;
import com.ericsson.enap.modules.autoCheck.mapper.AutoCheckLogMapper;
import com.ericsson.enap.modules.autoCheck.mapper.AutoCheckLogMaxtimeMapper;
import com.ericsson.enap.modules.autoCheck.mapper.AutomqDictImsMapper;
import com.ericsson.enap.modules.autoCheck.mapper.AutomqDictMapper;
import com.ericsson.enap.modules.autoCheck.mapper.NetAutoCheckMapper;
import com.ericsson.enap.modules.autoCheck.mapper.NetImsMapper;
import com.ericsson.enap.modules.autoCheck.mapper.VisAutoCheckLogMapper;
import com.ericsson.enap.modules.autoCheck.mapper.VisAutoCheckMqIdGeneratorMapper;
import com.ericsson.enap.modules.autoCheck.mapper.VisAutoCheckMqMapper;
import com.ericsson.enap.modules.autoCheck.mapper.VisExcelMapper;
import com.ericsson.enap.modules.autoCheck.mapper.VisExcelModuleDetailMapper;
import com.ericsson.enap.modules.autoCheck.service.EopsTemplateScheduleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class EopsTemplateScheduleServiceImpl implements EopsTemplateScheduleService {


    @Resource
    private NetAutoCheckMapper netAutoCheckMapper;

    @Resource
    private VisExcelMapper visExcelMapper;

    @Resource
    private VisExcelModuleDetailMapper moduleDetailMapper;

    @Resource
    private VisAutoCheckLogMapper visAutoCheckLogMapper;
    
    @Resource
    private VisAutoCheckMqMapper visAutoCheckMqMapper;
    
    @Resource
    private AutomqDictMapper automqDictMapper;

    @Resource
    private AutomqDictImsMapper automqDictImsMapper;

    @Resource
    private NetImsMapper netImsMapper;
    
    @Resource
    VisAutoCheckMqIdGeneratorMapper visAutoCheckMqIdGeneratorMapper;

    @Resource
    AutoCheckLogMapper autoCheckLogMapper;

    @Resource
    AutoCheckLogMaxtimeMapper autoCheckLogMaxtimeMapper;

    @Override
    public List<VisExcel> getBizTemplates(String types) {
        return visExcelMapper.getBizTemplates(types);
    }

    @Override
    public List<VisExcelModuleDetail> getModuleDetailsByExcelIds(String ids) {
        return moduleDetailMapper.getModuleDetailsByExcelIds(ids);
    }

    @Override
    public List<NetAutoCheck> getWorkingElementsByIP(String ip) {
        List<NetAutoCheck> workingElements = new ArrayList<>();
       /* workingElements.addAll(netMapper.getEopsWorkingNets(ip));
        workingElements.addAll(netMapper.getEopsWorkingOthers(ip));*/
        if(null == ip) {
            workingElements.addAll(netAutoCheckMapper.getListAll());
        } else {
            workingElements.addAll(netAutoCheckMapper.getEopsWorkingIms(ip));
        }
        return workingElements;
    }

    @Override
    public void insertAutoCheckLog(VisAutoCheckLog visAutoCheckLog) {
        visAutoCheckLogMapper.insert(visAutoCheckLog);
    }

	@Override
	public List<VisAutoCheckMq> getAutoCheckMqList() {
		return visAutoCheckMqMapper.getAutoCheckMqList();
	}

	@Override
	public void updateAutoCheckMq(VisAutoCheckMq visAutoCheckMq) {
		visAutoCheckMqMapper.updateAutoCheckMq(visAutoCheckMq);
	}

	@Override
	public List<AutomqDict> getAutomqDicList() {
		return automqDictMapper.getAutomqDicList();
	}

    @Override
    public List<AutomqDictIms> getAutomqDicImsList() {
        return automqDictImsMapper.getAutomqDicImsList();
    }

    @Override
	public List<VisAutoCheckLog> getCurrentTimeAlarm() {
		return visAutoCheckLogMapper.getCurrentTimeAlarm();
	}

	@Override
	public void insertAutoCheckMq(VisAutoCheckMq visAutoCheckMq) {
		visAutoCheckMqMapper.insertAutoCheckMq(visAutoCheckMq);
		
	}

	@Override
	public void updateIdValue(VisAutoCheckMqIdGenerator visAutoCheckMqIdGenerator) {
		visAutoCheckMqIdGeneratorMapper.updateIdValue(visAutoCheckMqIdGenerator);
		
	}

    @Override
    public List<NetIms> getNetImsList() {
        return netImsMapper.getListAll();
    }

    @Override
    public void cleanOldData(String cleanDate) {
        visAutoCheckLogMapper.deleteOldCheckLogData(cleanDate,"alarm");
        visAutoCheckLogMapper.deleteOldCheckLogData(cleanDate,"inspection");
        visAutoCheckLogMapper.deleteOldCheckLogData(cleanDate,"log");
        visAutoCheckLogMapper.deleteOldMqData(cleanDate);

    }

    @Override
    public void insertAutoCheck(AutoCheck autoCheck) {
        autoCheckLogMapper.insertAutoCheck(autoCheck);
    }

    @Override
    public void insertAutoCheckItem(List<AutoCheckItem> autoCheckItem) {
        autoCheckLogMapper.insertAutoCheckItem(autoCheckItem);
    }
    @Override
    public List<AutoCheckItem> selectAutoCheckItem(AutoCheckItem autoCheckItem) {
        return autoCheckLogMapper.selectAutoCheckItem(autoCheckItem);
    }

    @Override
    public void insertAutoCheckMaxtime(AutocheckMaxtime autocheckMaxtime) {
        autoCheckLogMaxtimeMapper.insertAutoCheckMaxtime(autocheckMaxtime);
    }

    @Override
    public void updateAutoCheckMaxtime(AutocheckMaxtime autocheckMaxtime) {
        autoCheckLogMaxtimeMapper.updateAutoCheckMaxtime(autocheckMaxtime);
    }

    @Override
    public List<AutocheckMaxtime> listAutoCheckMaxtime() {
        return autoCheckLogMaxtimeMapper.listAutoCheckMaxtime();
    }

    @Override
    public List<AutoCheck> getCurrentAlarm() {
        return autoCheckLogMapper.getCurrentTimeAlarm();
    }

    @Override
    public void cleanAutoCheck(String cleanDate) {
        List<AutoCheck> autoCheckList = autoCheckLogMapper.selectOldCheckLogData(cleanDate);
        for(AutoCheck ac : autoCheckList) {
            Long id = ac.getId();
            AutoCheckItem item = new AutoCheckItem();
            item.setAutocheckId(id);
            autoCheckLogMapper.deleteItem(item);
            autoCheckLogMapper.deleteAutoCheck(ac);
        }
    }

    @Override
	public VisAutoCheckMqIdGenerator getIdByType(String type) {
		return visAutoCheckMqIdGeneratorMapper.getIdByType(type);
	}



}
